import { createSlice ,PayloadAction} from "@reduxjs/toolkit";
export type UserStateType={
    username:string,
    nickname:string,
}
//初始化信息
const INIT_STATE:UserStateType={username:'',nickname:''}
export const userSlice=createSlice({
    name:'user',
    initialState:INIT_STATE,
    reducers:{
        loginReducer:(state:UserStateType,action:PayloadAction<UserStateType>)=>{
            return action.payload //设置username nickname 到redux store 中
        },
        logoutReducer:()=>INIT_STATE,
    }
})
export const {loginReducer,logoutReducer}=userSlice.actions
export default userSlice.reducer